<template>
    <div class="container-full">
        <!-- <div class="page-top" v-if="this.$store.state.options.user.oda.notice != null">
            <dl class="notice">
                <dt><img src="../../../static/images/notice-red-mini.png" /></dt>
                <dd @click="$router.push('/public/message-detail?id=' + $store.state.options.user.oda.notice.id)">{{ $store.state.options.user.oda.notice.title }}</dd>
            </dl>
        </div> -->
        <van-tabs v-model="tabs.index" color="#00CC00" class="order-list-items">
            <van-tab title="待收取">
                <van-list v-model="collect.loading" :finished="collect.finished" finished-text="没有更多了" @load="onLoad(collect.textType)">
                    <normal-order-list v-for="(item, index) in collect.dataset" :key="index"
                        :ibase="item.base" :dataset="item.items" :textType="collect.textType" class="el-item"
                    />
                </van-list>
            </van-tab>
            <van-tab title="待确认">
                <van-list v-model="confirm.loading" :finished="confirm.finished" finished-text="没有更多了" @load="onLoad(confirm.textType)">
                    <normal-order-list v-for="(item, index) in confirm.dataset" :key="index"
                        @onDelete="eventOnDeleteOrderItem(index)"
                        :ibase="item.base" :dataset="item.items" :textType="confirm.textType" class="el-item"
                    />
                </van-list>
            </van-tab>
            <van-tab title="已完成">
                <van-list v-model="complete.loading" :finished="complete.finished" finished-text="没有更多了" @load="onLoad(complete.textType)">
                    <normal-order-list v-for="(item, index) in complete.dataset" :key="index"
                        :ibase="item.base" :dataset="item.items" :textType="complete.textType" class="el-item"
                    />
                </van-list>
            </van-tab>
        </van-tabs>
        <tab-group :dataset="navButtonGroup" index="0" identity="2"></tab-group>
    </div>
</template>

<style lang="scss" scoped>
     .page-top {
        width: 100%;
        height: 3rem;
        position: relative;

        .notice {
            position: absolute;
            top: 0rem;
            width: 100%;
            margin: 0rem;
            padding: 0.7rem 1rem;
            display: flex;
            background:rgba(255,247,209,1);
            z-index: 1;
            box-sizing: border-box;
            dt {
                padding-right: 1rem;

                img {
                    width: 1.4rem;
                }
            }
            dd {
                white-space : nowrap;
                flex: 1;
                margin: 0rem;
                padding: 0rem;
                color: #FF9000;
                font-size: 1.3rem;
            }
        }
    }

     .order-list-items {
            position: relative;
         margin-bottom: 4rem;
         .el-item {
             padding: 0.5rem 1rem;
         }
     }
</style>

<script>
    import { Cell, CellGroup, Tab, Tabs, List } from 'vant';

    import NormalOrderList from '../../components/currency/order-item/normal-list-salesman.vue';
    import TabGroup from "../../components/currency/tab/tab.vue";

    export default {
        name: 'SalesmanIndex',
        components: {
            [Cell.name]: Cell, [CellGroup.name]: CellGroup,
            [Tab.name]: Tab, [Tabs.name]: Tabs, [List.name]: List,
            NormalOrderList, TabGroup
        },
        data() {
            return {
                navButtonGroup: [
                    {
                        name: "门店订单", route: { path:'/salesman/index'}
                    },
                    {
                        name: "待取点", route: { path:'/salesman/waiting-point-map'}
                    },
                    {
                        name: "查询报价", route: { path:'/salesman/enquiry-quotation'}
                    },
                    {
                        name: "个人中心", route: { path:'/salesman/personal-center'}
                    }
                ],
                tabs: {
                    index: 0, name: ''
                },
                collect: {
                    page: 0, list_rows: 10,
                    loading: false, finished: false,
                    textType: 'collect',
                    dataset: []
                },
                confirm: {
                    page: 0, list_rows: 10,
                    loading: false, finished: false,
                    textType: 'confirm',
                    dataset: []
                },
                complete: {
                    page: 0, list_rows: 10,
                    loading: false, finished: false,
                    textType: 'complete',
                    dataset: []
                }
            }
        },
        methods: {
            getOrderList(items) {
                // console.log(window.sessionStorage.getItem("res"));
                var that = this, status = '';
                switch (items.textType) {
                    case 'collect':
                        status = 1;
                        break;
                    case 'confirm':
                        status = 4;
                        break;
                    case 'complete':
                        status = 5;
                        break;
                }
                var url = '/api/home/order/getlist';
                var param = {
                    page: items.page,
                    list_rows: items.list_rows,
                    status: status,
                    shop_id: '',
                    token: that.$store.state.options.user.token
                };
                var detail = [];
                this.$util.postRequestInterface(url, param, (res) => {
                    items.page = items.page + 1;
                    if (res.data == '') {
                        items.loading = false;
                        items.finished = true;
                    } else {
                        for (let i of res.data.data) {
                            for (let x of i.detail) {
                                detail.push({
                                    title: x.garbagename,
                                    // number: x.weighting_method == 1 ? parseInt(x.weighting_num) : '',
                                    // weight: x.weighting_method == 0 ? x.weighting_num : '',
                                    number: x.weighting_num,
                                    unit: x.danweiming,
                                    danweiming: x.danweiming,
                                    time: that.$moment(i.create_time * 1000).format('YYYY-MM-DD HH:mm:ss'),
                                });
                            }
                            items.dataset.push({
                                base: {
                                    number: i.ordernumber,
                                    amount: i.price,
                                    name:i.username,
                                    time:that.$moment(i.create_time * 1000).format('YYYY-MM-DD HH:mm:ss')
                                },
                                items: detail
                            });
                            detail = [];
                        }
                        // // 加载状态结束
                        items.loading = false;
                        // // 数据全部加载完成
                        if (items.dataset.length >= res.data.count) {
                            items.finished = true;
                        }
                    }
                });
            },
            onLoad(textType) {
                switch (textType) {
                    case 'collect':
                        this.getOrderList(this.collect);
                        break;
                    case 'confirm':
                        this.getOrderList(this.confirm);
                        break;
                    case 'complete':
                        this.getOrderList(this.complete);
                        break;
                }
            },
            eventOnDeleteOrderItem(index) {
                this.confirm.dataset.splice(index, 1);
            }
        }
    }
</script>
